<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="__STATIC__/js/jquery.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table-zh-CN.min.js"></script>
    <script src="__STATIC__/bootstrap-table/js/dropdown.js"></script>
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap-table.min.css">
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap.css">
    <script type="text/javascript" src="__STATIC__/x-admin/js/xadmin.js"></script>
    <link rel="stylesheet" href="__STATIC__/x-admin/css/font.css">
    <link rel="stylesheet" href="__STATIC__/x-admin/css/xadmin.css">
    <script src="__STATIC__/js/common.js"></script>
</head>
<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="#">资源管理</a>
        <a href="#">视频课程</a>
        <a href="#">分类管理</a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.reload();" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<xblock>
    <button class="layui-btn" id="add"><i class="layui-icon"></i>添加分类</button>
</xblock>
<table class="table table-bordered" >
    <tr>
        <th align="center" valign="middle" class="borderright">id号</th>
        <th align="center" valign="middle" class="borderright">分类名称</th>
        <th align="center" valign="middle">操作</th>
    </tr>
    {foreach($data as $val)}
    <tr id="del{$val.cat_id}" >
        <td >{$val.cat_id}</td>
        <td >{$val.cat_name}</td>
        <td >
            <a href="#"><button type="button" onclick="edit({$val.cat_id})" class="btn btn-info btn-xs">编辑</button></a>&nbsp;&nbsp;
            <a href="#"><button type="button" onclick="del({$val.cat_id})" class="btn btn-danger btn-xs">删除</button></a>
        </td>
    </tr>
    {/foreach}
</table>
</body>
<script>
    //添加分类
    $("#add").click(function () {
        layer.prompt({title: '请输入分类名称'},function(val, index){
            $.ajax({
                url:"{:url('/video_type/addTypeInfo')}",
                data:{cat_name:val},
                type:"post",
                dataType:"json",
                beforeSend:function () {
                    index = layer.load(2, {time: 100*1000});
                },
                success:function(res){
                    if(res.code){
                        layer.close(index);
                        layer.msg(res.msg,{icon:1,time:2000},function(){
                            location.reload()
                        });
                        return;
                    }else{
                        layer.msg(res.msg,{icon:5,time:2000});
                        return;
                    }
                }
            })
            layer.close(index);
        });
    })
    //删除
    function del(cat_id){
        layer.confirm('你确定要删除吗',{btn:['确定','取消']},function(){
            $.ajax({
                url:"{:url('/video_type/deleteTypeInfo')}",
                type:"post",
                data:{id:cat_id},
                dataType:'json',
                beforeSend:function () {
                    index = layer.load(2, {time: 100*1000});
                },
                success:function(res){
                    if(res.code){
                        layer.close(index);
                        layer.msg(res.msg,{icon:1,time:2000},function(){
                            $("#del"+cat_id).remove();
                        });
                    }else{
                        layer.msg(res.msg,{icon:5,time:2000});
                    }
                }
            });
        });
    }
    //编辑
    function edit(cat_id){
            layer.prompt({title: '请输入更改后分类名称'},function(val, index){
                $.ajax({
                    url:"{:url('/video_type/updateTypeInfo')}",
                    data:{cat_name:val,id:cat_id},
                    type:"post",
                    dataType:"json",
                    beforeSend:function () {
                        index = layer.load(2, {time: 100*1000});
                    },
                    success:function(res){
                        if(res.code){
                            layer.close(index);
                            layer.msg(res.msg,{icon:1,time:2000},function(){
                                location.reload()
                            });
                            return;
                        }else{
                            layer.msg(res.msg,{icon:5,time:2000});
                            return;
                        }
                    }
                })
                layer.close(index);
            });
        }
</script>
</html>